import QtQuick 2.0
import QtQuick.Controls 2.0
import QtWebEngine 1.0

Item {
	property var item
	signal itemSelected(var data)

	WebEngineView {
		id: webView
		width: parent.width
		height: parent.height

		onNavigationRequested: {
			console.log("navigation requested");
			console.log(request.navigationType);
			console.log(request.url);

			if(request.navigationType !== WebEngineNavigationRequest.TypedNavigation) {
				var uri = Qt.resolvedUrl(request.url);
				if(uri.indexOf("gospellibrary://content/") === 0) {
					request.action = WebEngineNavigationRequest.IgnoreRequest;
					itemSelected({uri: uri.substring(23)});
				}
			}
		}
	}

	Component.onCompleted: {
		console.log("loading content");
		webView.loadHtml(item.body);
		console.log("hmmfwqe: " + width + ", " + height + ", " + x);
	}
}
